package com.king.edu.controller;

import com.king.edu.pojo.Resume;
import com.king.edu.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

/**
 * @ClassName: ResumeController
 * @Description: TODO
 * @Author: wangchangyong
 * @Date: 2020/4/16 10:41
 * @Version: 1.0.0
 **/
@Controller
@RequestMapping("/resume")
public class ResumeController {

    @Autowired
    ResumeService resumeService;

    @RequestMapping("/addPage")
    public String addPage() {
        return "resume/addResume";
    }

    @RequestMapping("/updatePage/{id}")
    public String updatePage(@PathVariable("id") String id, Map<String, Object> map) {
        map.put("content", resumeService.findById(Long.valueOf(id)));
        return "resume/updateResume";
    }

    @RequestMapping("/add")
    public String add(Map<String, Object> map, Resume resume) {
        resumeService.add(resume);
        map.put("content", resumeService.findAll());
        return "redirect:/main";
    }

    @RequestMapping("/update")
    public String update(Map<String, Object> map, Resume resume) {
        resumeService.update(resume);
        map.put("content", resumeService.findAll());
        return "redirect:/main";
    }

    @RequestMapping("/delete/{id}")
    public String add(@PathVariable("id") String id) {
        resumeService.delete(Long.valueOf(id));
        return "redirect:/main";
    }
}
